package ljl.alg.wangzheng_camp.round1.find_the_law;

public class _240_search_matrix_2 {
    
    /**
     * 不就一层循环吗？
     *
     * 早背的滚瓜烂熟了，呵呵...
     * */
    public boolean searchMatrix(int[][] matrix, int target) {
        if (matrix.length == 0) return false;
        int m = matrix.length, n = matrix[0].length;
        int i = 0, j = n - 1;
        while (i < m && j > -1) {
            if (matrix[i][j] == target)
                return true;
            if (matrix[i][j] < target)
                i++;
            else
                j--;
        }
        return false;
    }
}
